
#ifndef __IMAGECTRL_H__
#define __IMAGECTRL_H__

#include <string>
#include "ximage.h"

class ImageCtrl
{
public:
	class Callback
	{
	public:
		virtual void OnClick(ImageCtrl* imagectrl) = 0;
	};

	struct ResInfo
	{
		int resid;				//IDR_CLOSE
		const WCHAR* type;		//RT_BITMAP, "PNG"
		int format;				//CXIMAGE_FORMAT_BMP, CXIMAGE_FORMAT_PNG

		static ResInfo MakeResInfo(int resid, const WCHAR* type, int format)
		{
			ResInfo resinfo = {resid, type, format};
			return resinfo;
		}
	};

	enum Status
	{
		status_normal,
		status_hover,
		status_down
	};

public:
	ImageCtrl(void);
	virtual ~ImageCtrl(void);
	virtual void Load(const WCHAR* normal_imgfilename, const WCHAR* hover_imgfilename, const WCHAR* down_imgfilename);
	virtual void Load(const ResInfo* normal, const ResInfo* hover, const ResInfo* down);
	virtual void SetRect(const RECT& rect);
	virtual void SetCallback(Callback* callback);
	virtual RECT GetRect();
	virtual SIZE GetImageSize();
	virtual void Draw(HDC dc);
	virtual bool MouseMove(const POINT& point);
	virtual bool MouseDown(const POINT& point);
	virtual bool MouseUp(const POINT& point);

protected:
	RECT m_rect;
	CxImage* m_normalimage;
	CxImage* m_hoverimage;
	CxImage* m_downimage;
	Callback* m_callback;
	Status m_status;

	void LoadFromFile(const WCHAR* filename, CxImage** image);
	void LoadFromRes(const ResInfo* resinfo, CxImage** image);
	void ForceDraw();

};

#endif //__IMAGECTRL_H__
